﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace AsyncCallback
{
class MyPoint
{
    public int X;
    public int Y;
}

delegate void MyPointDelegate(MyPoint obj);

class MyPointClient
{
    public void Swap(MyPoint obj)
    {
        int temp = obj.X;
        obj.X = obj.Y;
        obj.Y = temp;
    }

    public void AysncSwap()
    {
        MyPoint point = new MyPoint();
        point.X = 3;
        point.Y = 4;

        MyPointDelegate swapDel = Swap;
        IAsyncResult asyncResult = swapDel.BeginInvoke(point, null, null);

        //BeginInvoke不改变引用类型的值
        //也不改变通过引用传递的值类型的值,这里无法保证.
        Debug.Assert(point.X == 3);
        Debug.Assert(point.Y == 4);

        swapDel.EndInvoke(asyncResult);

        Debug.Assert(point.X == 4);
        Debug.Assert(point.Y ==3);
        
    }
}
}
